<template>
  <div class="training-list-container">
    <div class="page-header">
      <h2>培养信息管理</h2>
      <p>管理用户的培养学习情况记录</p>
    </div>

    <!-- 统计卡片区域 -->
    <el-row :gutter="20" class="stat-cards">
      <el-col :span="6">
        <el-card shadow="hover" class="stat-card">
          <div class="stat-card-content">
            <div class="stat-icon bg-blue">
              <el-icon><Collection /></el-icon>
            </div>
            <div class="stat-info">
              <div class="stat-value">{{ statsData.totalCount }}</div>
              <div class="stat-label">培养记录总数</div>
            </div>
          </div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card shadow="hover" class="stat-card">
          <div class="stat-card-content">
            <div class="stat-icon bg-green">
              <el-icon><User /></el-icon>
            </div>
            <div class="stat-info">
              <div class="stat-value">{{ statsData.userCount }}</div>
              <div class="stat-label">培养对象人数</div>
            </div>
          </div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card shadow="hover" class="stat-card">
          <div class="stat-card-content">
            <div class="stat-icon bg-orange">
              <el-icon><Histogram /></el-icon>
            </div>
            <div class="stat-info">
              <div class="stat-value">{{ statsData.avgScore }}分</div>
              <div class="stat-label">平均考核成绩</div>
            </div>
          </div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card shadow="hover" class="stat-card">
          <div class="stat-card-content">
            <div class="stat-icon bg-purple">
              <el-icon><Calendar /></el-icon>
            </div>
            <div class="stat-info">
              <div class="stat-value">{{ statsData.activeCount }}</div>
              <div class="stat-label">当前培养人数</div>
            </div>
          </div>
        </el-card>
      </el-col>
    </el-row>

    <!-- 搜索和操作区域 -->
    <el-card class="search-card" shadow="hover">
      <div class="search-container">
        <el-form :inline="true" :model="searchForm" class="search-form">
          <el-form-item label="培养对象">
            <el-input 
              v-model="searchForm.name" 
              placeholder="请输入姓名" 
              clearable 
              @clear="handleInputClear('name')"
              @input="debounceSearch"
            />
          </el-form-item>
          <el-form-item label="培养阶段">
            <el-select 
              v-model="searchForm.status" 
              placeholder="请选择培养阶段" 
              clearable
              @change="handleStageChange"
            >
              <el-option label="入党积极分子" :value="1" />
              <el-option label="发展对象" :value="2" />
              <el-option label="预备党员" :value="3" />
              <el-option label="正式党员" :value="4" />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="searchTrainings">
              <el-icon><Search /></el-icon> 搜索
            </el-button>
            <el-button @click="resetSearch">
              <el-icon><Refresh /></el-icon> 重置
            </el-button>
          </el-form-item>
        </el-form>
        <div>
          <el-button type="success" @click="handleAdd">
            <el-icon><Plus /></el-icon> 新增培养记录
          </el-button>
        </div>
      </div>
    </el-card>

    <!-- 培养记录列表表格 -->
    <el-card class="table-card" shadow="hover" v-loading="loading">
      <el-table :data="trainingList" border style="width: 100%" row-key="id">
        <el-table-column type="index" label="序号" width="60" align="center" />
        <el-table-column prop="name" label="培养对象" min-width="100">
          <template #default="scope">
            {{ scope.row.name || getUserNameById(scope.row.userId) }}
          </template>
        </el-table-column>
        <el-table-column prop="status" label="培养阶段" min-width="120">
          <template #default="scope">
            {{ getStageText(scope.row.status) }}
          </template>
        </el-table-column>
        <el-table-column prop="trainingType" label="培养类型" min-width="120">
          <template #default="scope">
            {{ getTypeText(scope.row.trainingType) }}
          </template>
        </el-table-column>
        <el-table-column prop="recordTime" label="记录日期" min-width="120" />
        <el-table-column prop="trainingScore" label="考核分数" width="100" align="center">
          <template #default="scope">
            <el-tag :type="getScoreTagType(scope.row.trainingScore)">{{ scope.row.trainingScore }}分</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="操作" fixed="right" width="120">
          <template #default="scope">
            <div class="action-buttons">
              <el-button size="small" type="primary" plain @click="handleView(scope.row)">
                <el-icon><View /></el-icon> 查看
              </el-button>
              <el-button size="small" type="warning" plain @click="handleEdit(scope.row)">
                <el-icon><Edit /></el-icon> 编辑
              </el-button>
              <el-button size="small" type="danger" plain @click="handleDelete(scope.row)">
                <el-icon><Delete /></el-icon> 删除
              </el-button>
            </div>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页 -->
      <div class="pagination-container">
        <el-pagination
          v-model:current-page="currentPage"
          v-model:page-size="pageSize"
          :page-sizes="[10, 20, 50, 100]"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </el-card>

    <!-- 查看培养详情对话框 -->
    <el-dialog
      v-model="viewDialogVisible"
      title="培养详情"
      width="800px"
      :close-on-click-modal="false"
    >
      <el-descriptions :column="2" border>
        <el-descriptions-item label="培养对象">
          {{ currentTraining.name || getUserNameById(currentTraining.userId) }}
        </el-descriptions-item>
        <el-descriptions-item label="培养阶段">{{ getStageText(currentTraining.status) }}</el-descriptions-item>
        <el-descriptions-item label="培养类型">{{ getTypeText(currentTraining.trainingType) }}</el-descriptions-item>
        <el-descriptions-item label="记录日期">{{ currentTraining.recordTime }}</el-descriptions-item>
        <el-descriptions-item label="学习地点">{{ currentTraining.learningPlace }}</el-descriptions-item>
        <el-descriptions-item label="考核分数">
          <el-tag :type="getScoreTagType(currentTraining.trainingScore)">{{ currentTraining.trainingScore }}分</el-tag>
        </el-descriptions-item>
        <el-descriptions-item label="培养内容" :span="2">
          <div class="training-content">
            {{ currentTraining.trainingContent || '暂无内容' }}
          </div>
        </el-descriptions-item>
        <el-descriptions-item label="考核评价" :span="2">
          <div class="training-evaluation">
            {{ currentTraining.trainingReview || '暂无评价' }}
          </div>
        </el-descriptions-item>
        <el-descriptions-item label="培养人" >{{ currentTraining.trainingTeacher }}</el-descriptions-item>
        <el-descriptions-item label="学时">{{ currentTraining.trainingHour }}小时</el-descriptions-item>
      </el-descriptions>
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="viewDialogVisible = false">关闭</el-button>
        </div>
      </template>
    </el-dialog>

    <!-- 新增/编辑培养记录对话框 -->
    <el-dialog
      v-model="editDialogVisible"
      :title="isEdit ? '编辑培养记录' : '新增培养记录'"
      width="800px"
      :close-on-click-modal="false"
    >
      <el-form :model="trainingForm" :rules="trainingFormRules" ref="trainingFormRef" label-width="100px">
        <el-form-item label="培养对象" prop="userId">
          <el-select 
            v-model="trainingForm.userId" 
            filterable 
            placeholder="请选择培养对象" 
            @change="handleUserChange"
            :loading="userLoading"
          >
            <el-option 
              v-for="user in userList" 
              :key="user.id" 
              :label="user.name || user.username || user.nickname || '用户' + user.id" 
              :value="user.id" 
            />
          </el-select>
          <div v-if="trainingForm.name" class="selected-user-info">
            已选择: {{ trainingForm.name }}
          </div>
        </el-form-item>
        <el-form-item label="培养阶段" prop="status">
          <el-select v-model="trainingForm.status" placeholder="请选择培养阶段" style="width: 100%">
            <el-option label="入党积极分子" :value="1" />
            <el-option label="发展对象" :value="2" />
            <el-option label="预备党员" :value="3" />
            <el-option label="正式党员" :value="4" />
          </el-select>
        </el-form-item>
        <el-form-item label="培养类型" prop="trainingType">
          <el-select v-model="trainingForm.trainingType" placeholder="请选择培养类型" style="width: 100%">
            <el-option label="党课学习" value="party_class" />
            <el-option label="理论学习" value="theory" />
            <el-option label="实践活动" value="practice" />
            <el-option label="志愿服务" value="volunteer" />
            <el-option label="组织生活" value="organization" />
          </el-select>
        </el-form-item>
        <el-form-item label="记录日期" prop="recordTime">
          <el-date-picker
            v-model="trainingForm.recordTime"
            type="date"
            placeholder="请选择记录日期"
            format="YYYY-MM-DD"
            value-format="YYYY-MM-DD"
            style="width: 100%"
          />
        </el-form-item>
        <el-form-item label="学习地点" prop="learningPlace">
          <el-input v-model="trainingForm.learningPlace" placeholder="请输入学习地点" />
        </el-form-item>
        <el-form-item label="培养人" prop="trainingTeacher">
          <el-input v-model="trainingForm.trainingTeacher" placeholder="请输入培养人姓名" />
        </el-form-item>
        <el-form-item label="学时" prop="trainingHour">
          <el-input-number v-model="trainingForm.trainingHour" :min="1" :max="100" placeholder="请输入学时" style="width: 100%" />
        </el-form-item>
        <el-form-item label="考核分数" prop="trainingScore">
          <el-slider v-model="trainingForm.trainingScore" :step="1" :min="0" :max="100" show-input/>
        </el-form-item>
        <el-form-item label="培养内容" prop="trainingContent">
          <el-input 
            v-model="trainingForm.trainingContent" 
            type="textarea" 
            :rows="5" 
            placeholder="请输入培养内容"
          />
        </el-form-item>
        <el-form-item label="考核评价" prop="trainingReview">
          <el-input 
            v-model="trainingForm.trainingReview" 
            type="textarea" 
            :rows="3" 
            placeholder="请输入考核评价"
          />
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="editDialogVisible = false">取消</el-button>
          <el-button type="primary" @click="submitTraining" :loading="submitting">保存</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup>
import { ref, reactive, onMounted, computed } from 'vue';
import { ElMessage, ElMessageBox } from 'element-plus';
import { 
  Search, Refresh, View, Edit, Delete, Plus, Collection, 
  User, Histogram, Calendar
} from '@element-plus/icons-vue';
import { 
  getTrainingLogList, 
  getTrainingLogById, 
  addTrainingLog, 
  updateTrainingLog, 
  deleteTrainingLog
} from '@/api/trainingLog';
import { getUserList } from '@/api/user';

// 分页相关
const currentPage = ref(1);
const pageSize = ref(10);
const total = ref(0);
const loading = ref(false);
const trainingList = ref([]);

// 用户列表数据
const userList = ref([]);
const userLoading = ref(false);

// 统计数据
const statsData = reactive({
  totalCount: 0,
  userCount: 0,
  avgScore: 0,
  activeCount: 0
});

// 搜索表单
const searchForm = reactive({
  name: '',
  status: ''
});

// 详情对话框
const viewDialogVisible = ref(false);
const currentTraining = ref({});

// 编辑对话框
const editDialogVisible = ref(false);
const isEdit = ref(false);
const trainingFormRef = ref(null);
const trainingForm = reactive({
  id: '',                  // 主键id
  userId: '',              // 培养对象id
  name: '',                // 培养对象姓名(只用于显示，不提交)
  status: '',              // 培养阶段 (之前是stage)
  trainingType: '',        // 培养类型 (之前是type)
  recordTime: '',          // 记录日期 (之前是date)
  learningPlace: '',       // 学习地点 (之前是location)
  trainingTeacher: '',     // 培养人 (之前是trainer)
  trainingHour: 2,         // 学时 (之前是hours)
  trainingScore: 80,       // 考核分数 (之前是score)
  trainingContent: '',     // 培养内容 (之前是content)
  trainingReview: ''       // 考核评价 (之前是evaluation)
});
const submitting = ref(false);

// 表单校验规则
const trainingFormRules = {
  userId: [{ required: true, message: '请选择培养对象', trigger: 'change' }],
  status: [{ required: true, message: '请选择培养阶段', trigger: 'change' }],
  trainingType: [{ required: true, message: '请选择培养类型', trigger: 'change' }],
  recordTime: [{ required: true, message: '请选择记录日期', trigger: 'change' }],
  learningPlace: [{ required: true, message: '请输入学习地点', trigger: 'blur' }],
  trainingTeacher: [{ required: true, message: '请输入培养人姓名', trigger: 'blur' }],
  trainingHour: [{ required: true, message: '请输入学时', trigger: 'blur' }],
  trainingScore: [{ required: true, message: '请输入考核分数', trigger: 'blur' }],
  trainingContent: [{ required: true, message: '请输入培养内容', trigger: 'blur' }]
};

// 初始化加载数据
onMounted(() => {
  fetchUsers();
  fetchTrainings();
});

// 获取用户列表
const fetchUsers = async () => {
  userLoading.value = true;
  try {
    const response = await getUserList();
    if (response.data.code === 200) {
      userList.value = response.data.data.users || [];
    } else {
      ElMessage.error(response.data.msg || '获取用户列表失败');
    }
  } catch (error) {
    console.error('获取用户列表失败:', error);
    ElMessage.error('获取用户列表失败，请稍后重试');
  } finally {
    userLoading.value = false;
  }
};

// 获取培养记录列表
const fetchTrainings = async () => {
  loading.value = true;
  try {
    // 构建查询条件
    const queryData = {
      name: searchForm.name,
      status: searchForm.status
    };
    
    // 调用API获取数据
    const response = await getTrainingLogList(queryData, currentPage.value, pageSize.value);
    
    if (response.data.code === 200) {
      const data = response.data.data || {};
      trainingList.value = data.page?.records || [];
      total.value = data.total || 0;
      
      // 确保用户列表已加载
      if (userList.value.length === 0) {
        await fetchUsers();
      }
      
      // 尝试为没有姓名的记录填充姓名
      trainingList.value.forEach(item => {
        if (!item.name && item.userId) {
          item.name = getUserNameById(item.userId);
        }
      });
      
      // 计算统计数据
      updateStatsData();
    } else {
      ElMessage.error(response.data.msg || '获取培养记录列表失败');
      // 清空数据
      trainingList.value = [];
      total.value = 0;
      updateStatsData();
    }
  } catch (error) {
    console.error('获取培养记录列表失败:', error);
    ElMessage.error('获取培养记录列表失败，请稍后重试');
    // 清空数据
    trainingList.value = [];
    total.value = 0;
    updateStatsData();
  } finally {
    loading.value = false;
  }
};

// 更新统计数据
const updateStatsData = () => {
  // 计算总数
  statsData.totalCount = trainingList.value.length;
  
  // 计算涉及的培养对象人数（去重）
  const uniqueNames = new Set();
  trainingList.value.forEach(item => uniqueNames.add(item.name));
  statsData.userCount = uniqueNames.size;
  
  // 计算平均考核分数
  let totalScore = 0;
  trainingList.value.forEach(item => {
    totalScore += item.trainingScore;
  });
  statsData.avgScore = trainingList.value.length ? Math.round(totalScore / trainingList.value.length) : 0;
  
  // 计算当前培养人数 (按阶段进行不同计算，这里简化为积极分子和发展对象的总数)
  statsData.activeCount = trainingList.value.filter(
    item => item.status === 'activist' || item.status === 'development'
  ).length;
};

// 搜索培养记录
const searchTrainings = () => {
  currentPage.value = 1;
  fetchTrainings();
};

// 重置搜索条件
const resetSearch = () => {
  Object.keys(searchForm).forEach(key => {
    searchForm[key] = '';
  });
  currentPage.value = 1;
  fetchTrainings();
};

// 处理分页大小变化
const handleSizeChange = (val) => {
  pageSize.value = val;
  fetchTrainings();
};

// 处理页码变化
const handleCurrentChange = (val) => {
  currentPage.value = val;
  fetchTrainings();
};

// 处理输入框清除
const handleInputClear = (key) => {
  searchForm[key] = '';
  fetchTrainings();
};

// 处理类型变化
const handleStageChange = () => {
  fetchTrainings();
};

// 获取培养阶段文本
const getStageText = (status) => {
  const stages = {
    1: '入党积极分子',
    2: '发展对象',
    3: '预备党员',
    4: '正式党员',
    // 兼容字符串类型的编码
    'activist': '入党积极分子',
    'development': '发展对象',
    'probationary': '预备党员',
    'formal': '正式党员'
  };
  return stages[status] || status;
};

// 获取培养类型文本
const getTypeText = (type) => {
  const types = {
    'party_class': '党课学习',
    'theory': '理论学习',
    'practice': '实践活动',
    'volunteer': '志愿服务',
    'organization': '组织生活'
  };
  return types[type] || type;
};

// 获取分数标签类型
const getScoreTagType = (score) => {
  if (score >= 90) return 'success';
  if (score >= 75) return '';
  if (score >= 60) return 'warning';
  return 'danger';
};

// 查看培养详情
const handleView = (row) => {
  currentTraining.value = { ...row };
  
  // 如果没有名称但有userId，尝试从用户列表获取名称
  if (!currentTraining.value.name && currentTraining.value.userId) {
    currentTraining.value.name = getUserNameById(currentTraining.value.userId);
  }
  
  viewDialogVisible.value = true;
};

// 处理编辑培养记录
const handleEdit = (row) => {
  isEdit.value = true;
  
  // 清空表单
  Object.keys(trainingForm).forEach(key => {
    trainingForm[key] = '';
  });
  
  // 填充表单数据
  trainingForm.id = row.id;
  trainingForm.userId = row.userId;
  trainingForm.name = row.name; // 用于显示，不提交
  trainingForm.status = row.status;
  trainingForm.trainingType = row.trainingType;
  trainingForm.recordTime = row.recordTime;
  trainingForm.learningPlace = row.learningPlace;
  trainingForm.trainingTeacher = row.trainingTeacher;
  trainingForm.trainingHour = row.trainingHour;
  trainingForm.trainingScore = row.trainingScore;
  trainingForm.trainingContent = row.trainingContent;
  trainingForm.trainingReview = row.trainingReview;
  
  editDialogVisible.value = true;
};

// 新增培养记录
const handleAdd = () => {
  isEdit.value = false;
  
  // 重置表单
  Object.keys(trainingForm).forEach(key => {
    if (key === 'trainingHour') {
      trainingForm[key] = 2;
    } else if (key === 'trainingScore') {
      trainingForm[key] = 80;
    } else {
      trainingForm[key] = '';
    }
  });
  
  // 设置默认创建时间
  trainingForm.recordTime = new Date().toISOString().split('T')[0];
  
  editDialogVisible.value = true;
};

// 删除培养记录
const handleDelete = (row) => {
  ElMessageBox.confirm(
    `确定要删除"${row.name}"的培养记录吗？此操作不可恢复！`,
    '警告',
    {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning'
    }
  ).then(async () => {
    try {
      loading.value = true;
      // 调用API删除数据
      const response = await deleteTrainingLog(row.id);
      
      if (response.data.code === 200) {
        ElMessage.success(`删除"${row.name}"的培养记录成功`);
        await fetchTrainings(); // 刷新列表并更新统计数据
      } else {
        ElMessage.error(response.data.msg || '删除失败');
      }
    } catch (error) {
      console.error('删除培养记录失败:', error);
      ElMessage.error('删除失败，请稍后重试');
    } finally {
      loading.value = false;
    }
  }).catch(() => {});
};

// 提交培养记录
const submitTraining = async () => {
  if (!trainingFormRef.value) return;
  
  trainingFormRef.value.validate(async (valid) => {
    if (!valid) return;
    
    submitting.value = true;
    try {
      // 构建提交数据，包含userId
      const submitData = {
        id: trainingForm.id || undefined, // 新增时不需要ID
        userId: trainingForm.userId,    // 用户ID，必须提交
        status: trainingForm.status,
        trainingType: trainingForm.trainingType,
        recordTime: trainingForm.recordTime,
        learningPlace: trainingForm.learningPlace,
        trainingTeacher: trainingForm.trainingTeacher,
        trainingHour: trainingForm.trainingHour,
        trainingScore: trainingForm.trainingScore,
        trainingContent: trainingForm.trainingContent,
        trainingReview: trainingForm.trainingReview
      };
      
      // 调用API提交数据
      let response;
      
      if (isEdit.value) {
        // 更新已有记录
        response = await updateTrainingLog(submitData);
      } else {
        // 新增记录
        response = await addTrainingLog(submitData);
      }
      
      if (response.data.code === 200) {
        ElMessage.success(isEdit.value ? '更新培养记录成功' : '添加培养记录成功');
        editDialogVisible.value = false;
        await fetchTrainings(); // 刷新列表并更新统计数据
      } else {
        ElMessage.error(response.data.msg || (isEdit.value ? '更新失败' : '添加失败'));
      }
    } catch (error) {
      console.error('提交培养记录失败:', error);
      ElMessage.error('提交失败，请稍后重试');
    } finally {
      submitting.value = false;
    }
  });
};

// 即时搜索
const debounceSearch = () => {
  fetchTrainings();
};

// 处理用户选择变化
const handleUserChange = (userId) => {
  if (!userId) {
    trainingForm.name = '';
    return;
  }
  
  // 根据id查找用户信息
  const selectedUser = userList.value.find(user => user.id === userId);
  if (selectedUser) {
    // 显示用户姓名，但在提交时使用userId
    trainingForm.name = selectedUser.name || selectedUser.username || selectedUser.nickname || '未知用户';
  }
};

// 获取用户名
const getUserNameById = (userId) => {
  if (!userId) return '未知用户';
  
  // 确保userId是数字类型（后端可能返回字符串）
  const id = typeof userId === 'string' ? parseInt(userId, 10) : userId;
  
  // 查找用户信息
  const user = userList.value.find(u => u.id === id || u.id === userId);
  
  // 返回用户名，优先返回name字段
  return user ? (user.name || user.username || user.nickname || `用户${userId}`) : `用户${userId}`;
};
</script>

<style scoped>
.training-list-container {
  padding: 20px;
}

.page-header {
  margin-bottom: 20px;
}

.page-header h2 {
  font-size: 24px;
  color: #303133;
  margin: 0 0 8px 0;
}

.page-header p {
  font-size: 14px;
  color: #909399;
  margin: 0;
}

.stat-cards {
  margin-bottom: 20px;
}

.stat-card {
  margin-bottom: 20px;
}

.stat-card-content {
  display: flex;
  align-items: center;
  height: 100px;
  padding: 0 20px;
}

.stat-icon {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-right: 15px;
}

.stat-icon .el-icon {
  font-size: 28px;
  color: white;
}

.bg-blue {
  background-color: #409EFF;
}

.bg-green {
  background-color: #67C23A;
}

.bg-orange {
  background-color: #E6A23C;
}

.bg-purple {
  background-color: #909399;
}

.stat-info {
  flex: 1;
}

.stat-value {
  font-size: 24px;
  font-weight: bold;
  margin-bottom: 5px;
  color: #303133;
}

.stat-label {
  font-size: 14px;
  color: #909399;
}

.search-card {
  margin-bottom: 20px;
}

.search-container {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
}

.search-form {
  display: flex;
  flex-wrap: wrap;
}

.table-card {
  margin-bottom: 20px;
}

.pagination-container {
  margin-top: 20px;
  display: flex;
  justify-content: flex-end;
}

.dialog-footer {
  padding-top: 20px;
  text-align: right;
}

.training-content, .training-evaluation {
  white-space: pre-line;
  padding: 10px;
  background-color: #f5f7fa;
  border-radius: 4px;
  max-height: 200px;
  overflow-y: auto;
}

.action-buttons {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.action-buttons .el-button {
  margin-left: 0 !important;
  width: 100%;
}

.selected-user-info {
  margin-top: 5px;
  font-size: 12px;
  color: #409EFF;
  font-style: italic;
}

@media (max-width: 768px) {
  .search-container {
    flex-direction: column;
  }
}
</style> 